package logic

import (
	"context"
	"github.com/jinzhu/copier"

	"mall/app/product/cmd/rpc/internal/svc"
	"mall/app/product/cmd/rpc/pb"

	"github.com/zeromicro/go-zero/core/logx"
)

type GetProductInfoLogic struct {
	ctx    context.Context
	svcCtx *svc.ServiceContext
	logx.Logger
}

func NewGetProductInfoLogic(ctx context.Context, svcCtx *svc.ServiceContext) *GetProductInfoLogic {
	return &GetProductInfoLogic{
		ctx:    ctx,
		svcCtx: svcCtx,
		Logger: logx.WithContext(ctx),
	}
}

func (l *GetProductInfoLogic) GetProductInfo(in *pb.GetProductInfoReq) (*pb.GetProductInfoResp, error) {
	skuInfo, err := l.svcCtx.SkuInfoModel.FindOne(l.ctx, in.SkuId)
	if err != nil {
		return nil, err
	}
	res := pb.GetProductInfoResp{}
	_ = copier.Copy(&res, &skuInfo)
	return &res, nil
}
